﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 14/02/2009
// Time: 11:48
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Drawing;
using csharp.rad.general;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;

namespace csharp.rad.automaPlus
{
	/// <summary>
	/// Description of frmChooseCompany.
	/// </summary>
	public partial class frmChooseCompany : KryptonForm
	{
		private general.Companies listCompany = new general.Companies();
		private Configuration config = new Configuration();
		
		public frmChooseCompany()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
		
		}
		
		void FrmChooseCompanyLoad(object sender, EventArgs e)
		{
			listCompany.fillList();
			
			config.get();
			
			fillComboCompany();
			
			listCompany.search(config.defaultCompanyId);
			cmbCompany.SelectedIndex = listCompany.getIndex();
			
			ckbShowForm.Checked = Convert.ToBoolean(config.showFormChooseCompany);
		}
		
		private void fillComboCompany()
		{
			for (int i=0; i < listCompany.count(); i++)
				cmbCompany.Items.Add(listCompany.get(i).person);
			cmbCompany.DisplayMember = "name";
		}
		
		void CkbShowFormCheckedChanged(object sender, EventArgs e)
		{
			config.showFormChooseCompany = ckbShowForm.Checked;
		}
		
		void BtnOkClick(object sender, EventArgs e)
		{
			config.defaultCompanyId = listCompany.get(cmbCompany.SelectedIndex).id;
			Information.companyId 	= listCompany.get(cmbCompany.SelectedIndex).id;
			Information.companyName = ((general.Person)cmbCompany.SelectedItem).name;
			
			config.doSerialization();
			this.Close();
		}
	}
}
